{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import re\n", "from tqdm import tqdm\n", "import pickle\n", "import copy\n", "tqdm.pandas()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " title text \\\n", "0 ! #redirect 느낌표\\n \n", "1 !!아앗!! \\n[목차]\\n\\n'''{{{+1 !!ああっと!!}}}'''\\n\\n== 개요 ==\\... \n", "2 “……” ||<-2>\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
titletext
0!#redirect 느낌표\\n
1!!아앗!!\\n[목차]\\n\\n'''{{{+1 !!ああっと!!}}}'''\\n\\n== 개요 ==\\...
2“……”||<-2><tablebordercolor=#878787><tablealign=ri...
3#[[분류:특수 문자]]\\n[include(틀:다른 뜻1, other1=음악에서 사용...
4#FairyJoke[include(틀:링크시 주의, 링크=[[\\\\#FairyJoke]] 또는 [[#F...
.........
867019광저우 푸리#redirect 광저우 시티\\n
867020에스시더#redirect 이스시\\n
867021칭다오 황하이#redirect 칭다오 FC\\n
867022순혜옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...
867023허난 젠예#redirect 허난 쑹산 룽먼\\n
\n", "

867024 rows × 2 columns

\n", "" ], "text/plain": [ " title text\n", "0 ! #redirect 느낌표\\n\n", "1 !!아앗!! \\n[목차]\\n\\n'''{{{+1 !!ああっと!!}}}'''\\n\\n== 개요 ==\\...\n", "2 “……” ||<-2>\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
titletext
2“……”||<-2><tablebordercolor=#878787><tablealign=ri...
6#Fairy_dancing_in_lake[include(틀:링크시 주의, 링크=[[\\\\#Fairy_dancing_in_la...
14&(싱글)[include(틀:하마사키 아유미의 싱글)]\\n||||||<tablewidth=1...
18페텔기우스 로마네콩티[include(틀:다른 뜻1, other1=항성, rd1=베텔게우스)]\\n[inc...
19사테라(Re: 제로부터 시작하는 이세계 생활)[include(틀:토론 합의, 토론주소1=ANullAndFascinatedShoe...
.........
867012마른 남자||<table width=300><table bordercolor=#000><ta...
867014니나(로얄 크라운)[[분류:로얄 크라운]]\\n[include(틀:상위 문서, top1=로얄 크라운)]...
867015혜선옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...
867016아즈사 아이자와||<table width=100%><width=58%><tablebordercol...
867022순혜옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...
\n", "

283385 rows × 2 columns

\n", "" ], "text/plain": [ " title \\\n", "2 “……” \n", "6 #Fairy_dancing_in_lake \n", "14 &(싱글) \n", "18 페텔기우스 로마네콩티 \n", "19 사테라(Re: 제로부터 시작하는 이세계 생활) \n", "... ... \n", "867012 마른 남자 \n", "867014 니나(로얄 크라운) \n", "867015 혜선옹주 \n", "867016 아즈사 아이자와 \n", "867022 순혜옹주 \n", "\n", " text \n", "2 ||<-2>\n", "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
titletext
2“……”||<-2><tablebordercolor=#878787><tablealign=ri...
6#Fairy_dancing_in_lake[include(틀:링크시 주의, 링크=[[\\\\#Fairy_dancing_in_la...
14&(싱글)[include(틀:하마사키 아유미의 싱글)]\\n||||||<tablewidth=1...
18페텔기우스 로마네콩티[include(틀:다른 뜻1, other1=항성, rd1=베텔게우스)]\\n[inc...
19사테라(Re: 제로부터 시작하는 이세계 생활)[include(틀:토론 합의, 토론주소1=ANullAndFascinatedShoe...
.........
867012마른 남자||<table width=300><table bordercolor=#000><ta...
867014니나(로얄 크라운)[[분류:로얄 크라운]]\\n[include(틀:상위 문서, top1=로얄 크라운)]...
867015혜선옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...
867016아즈사 아이자와||<table width=100%><width=58%><tablebordercol...
867022순혜옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...
\n", "

274635 rows × 2 columns

\n", "" ], "text/plain": [ " title \\\n", "2 “……” \n", "6 #Fairy_dancing_in_lake \n", "14 &(싱글) \n", "18 페텔기우스 로마네콩티 \n", "19 사테라(Re: 제로부터 시작하는 이세계 생활) \n", "... ... \n", "867012 마른 남자 \n", "867014 니나(로얄 크라운) \n", "867015 혜선옹주 \n", "867016 아즈사 아이자와 \n", "867022 순혜옹주 \n", "\n", " text \n", "2 ||<-2>:1: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " filtered_df['text'] = filtered_df['text'].apply(lambda x: x.split('[목차]')[0])\n" ] }, { "data": { "text/html": [ "
\n", "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
titletext
2“……”||<-2><tablebordercolor=#878787><tablealign=ri...
6#Fairy_dancing_in_lake[include(틀:링크시 주의, 링크=[[\\\\#Fairy_dancing_in_la...
14&(싱글)[include(틀:하마사키 아유미의 싱글)]\\n||||||<tablewidth=1...
18페텔기우스 로마네콩티[include(틀:다른 뜻1, other1=항성, rd1=베텔게우스)]\\n[inc...
19사테라(Re: 제로부터 시작하는 이세계 생활)[include(틀:토론 합의, 토론주소1=ANullAndFascinatedShoe...
.........
867012마른 남자||<table width=300><table bordercolor=#000><ta...
867014니나(로얄 크라운)[[분류:로얄 크라운]]\\n[include(틀:상위 문서, top1=로얄 크라운)]...
867015혜선옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...
867016아즈사 아이자와||<table width=100%><width=58%><tablebordercol...
867022순혜옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...
\n", "

274635 rows × 2 columns

\n", "" ], "text/plain": [ " title \\\n", "2 “……” \n", "6 #Fairy_dancing_in_lake \n", "14 &(싱글) \n", "18 페텔기우스 로마네콩티 \n", "19 사테라(Re: 제로부터 시작하는 이세계 생활) \n", "... ... \n", "867012 마른 남자 \n", "867014 니나(로얄 크라운) \n", "867015 혜선옹주 \n", "867016 아즈사 아이자와 \n", "867022 순혜옹주 \n", "\n", " text \n", "2 ||<-2>:1: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " filtered_df['table_contents'] = filtered_df['text'].progress_apply(lambda x: get_table_contents(x))\n" ] }, { "data": { "text/html": [ "
\n", "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
titletexttable_contents
2“……”||<-2><tablebordercolor=#878787><tablealign=ri...[||<-2><tablebordercolor=#878787><tablealign=r...
6#Fairy_dancing_in_lake[include(틀:링크시 주의, 링크=[[\\\\#Fairy_dancing_in_la...[]
14&(싱글)[include(틀:하마사키 아유미의 싱글)]\\n||||||<tablewidth=1...[||||||<tablewidth=100%> '''[[하마사키 아유미]]의 싱글''...
18페텔기우스 로마네콩티[include(틀:다른 뜻1, other1=항성, rd1=베텔게우스)]\\n[inc...[||<tablealign=center><bgcolor=#ffffff> [[파일:페...
19사테라(Re: 제로부터 시작하는 이세계 생활)[include(틀:토론 합의, 토론주소1=ANullAndFascinatedShoe...[||<-2><bgcolor=#414a4c> {{{#white 애니메이션}}}[* ...
............
867012마른 남자||<table width=300><table bordercolor=#000><ta...[||<table width=300><table bordercolor=#000><t...
867014니나(로얄 크라운)[[분류:로얄 크라운]]\\n[include(틀:상위 문서, top1=로얄 크라운)]...[||<tablealign=center><tablewidth=70%><-2><bgc...
867015혜선옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...[||<-2><tablealign=right><tablewidth=400><tabl...
867016아즈사 아이자와||<table width=100%><width=58%><tablebordercol...[||<table width=100%><width=58%><tableborderco...
867022순혜옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...[||<-2><tablealign=right><tablewidth=400><tabl...
\n", "

274635 rows × 3 columns

\n", "" ], "text/plain": [ " title \\\n", "2 “……” \n", "6 #Fairy_dancing_in_lake \n", "14 &(싱글) \n", "18 페텔기우스 로마네콩티 \n", "19 사테라(Re: 제로부터 시작하는 이세계 생활) \n", "... ... \n", "867012 마른 남자 \n", "867014 니나(로얄 크라운) \n", "867015 혜선옹주 \n", "867016 아즈사 아이자와 \n", "867022 순혜옹주 \n", "\n", " text \\\n", "2 ||<-2> '''[[하마사키 아유미]]의 싱글''... \n", "18 [|| [[파일:페... \n", "19 [||<-2> {{{#white 애니메이션}}}[* ... \n", "... ... \n", "867012 [||
<-2> 2:\n", " splited_content = splited_content[-2:] \n", " predicate, objects = splited_content\n", " parsed_table_contents.append({'predicate': predicate, 'objects': objects})\n", " return parsed_table_contents" ] }, { "cell_type": "code", "execution_count": 230, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 274635/274635 [00:27<00:00, 9872.27it/s] \n", ":1: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " filtered_df['parsed_table_contents'] = filtered_df['table_contents'].progress_apply(lambda x: parse_table_contents(x))\n" ] }, { "data": { "text/html": [ "
\n", "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
titletexttable_contentsparsed_table_contents
2“……”||<-2><tablebordercolor=#878787><tablealign=ri...[||<-2><tablebordercolor=#878787><tablealign=r...[{'predicate': ' '''코너명''' ', 'objects': ' “……...
6#Fairy_dancing_in_lake[include(틀:링크시 주의, 링크=[[\\\\#Fairy_dancing_in_la...[][]
14&(싱글)[include(틀:하마사키 아유미의 싱글)]\\n||||||<tablewidth=1...[||||||<tablewidth=100%> '''[[하마사키 아유미]]의 싱글''...[{'predicate': '<width=40%> '''&''' (2003) ', ...
18페텔기우스 로마네콩티[include(틀:다른 뜻1, other1=항성, rd1=베텔게우스)]\\n[inc...[||<tablealign=center><bgcolor=#ffffff> [[파일:페...[{'predicate': '<bgcolor=#007f66> {{{#ffffff '...
19사테라(Re: 제로부터 시작하는 이세계 생활)[include(틀:토론 합의, 토론주소1=ANullAndFascinatedShoe...[||<-2><bgcolor=#414a4c> {{{#white 애니메이션}}}[* ...[]
...............
867012마른 남자||<table width=300><table bordercolor=#000><ta...[||<table width=300><table bordercolor=#000><t...[]
867014니나(로얄 크라운)[[분류:로얄 크라운]]\\n[include(틀:상위 문서, top1=로얄 크라운)]...[||<tablealign=center><tablewidth=70%><-2><bgc...[{'predicate': ' {{{#000,#fff '''클래스'''}}} ', ...
867015혜선옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...[||<-2><tablealign=right><tablewidth=400><tabl...[{'predicate': '<width=50> '''{{{#gold 본명}}}''...
867016아즈사 아이자와||<table width=100%><width=58%><tablebordercol...[||<table width=100%><width=58%><tableborderco...[{'predicate': '<rowbgcolor=#ffff99> [[전생했더니 슬...
867022순혜옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...[||<-2><tablealign=right><tablewidth=400><tabl...[{'predicate': '<width=50> '''{{{#gold 출생}}}''...
\n", "

274635 rows × 4 columns

\n", "" ], "text/plain": [ " title \\\n", "2 “……” \n", "6 #Fairy_dancing_in_lake \n", "14 &(싱글) \n", "18 페텔기우스 로마네콩티 \n", "19 사테라(Re: 제로부터 시작하는 이세계 생활) \n", "... ... \n", "867012 마른 남자 \n", "867014 니나(로얄 크라운) \n", "867015 혜선옹주 \n", "867016 아즈사 아이자와 \n", "867022 순혜옹주 \n", "\n", " text \\\n", "2 ||<-2> '''[[하마사키 아유미]]의 싱글''... \n", "18 [|| [[파일:페... \n", "19 [||<-2> {{{#white 애니메이션}}}[* ... \n", "... ... \n", "867012 [||
<-2> '''&''' (2003) ', ... \n", "18 [{'predicate': ' {{{#ffffff '... \n", "19 [] \n", "... ... \n", "867012 [] \n", "867014 [{'predicate': ' {{{#000,#fff '''클래스'''}}} ', ... \n", "867015 [{'predicate': ' '''{{{#gold 본명}}}''... \n", "867016 [{'predicate': ' [[전생했더니 슬... \n", "867022 [{'predicate': ' '''{{{#gold 출생}}}''... \n", "\n", "[274635 rows x 4 columns]" ] }, "execution_count": 230, "metadata": {}, "output_type": "execute_result" } ], "source": [ "filtered_df['parsed_table_contents'] = filtered_df['table_contents'].progress_apply(lambda x: parse_table_contents(x))\n", "filtered_df" ] }, { "cell_type": "code", "execution_count": 232, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":2: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " cnt_df['parsed_table_contents'] = cnt_df['parsed_table_contents'].apply(lambda x: len(x))\n" ] }, { "data": { "text/html": [ "
\n", "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
titleparsed_table_contents
2“……”5
6#Fairy_dancing_in_lake0
14&(싱글)1
18페텔기우스 로마네콩티1
19사테라(Re: 제로부터 시작하는 이세계 생활)0
.........
867012마른 남자0
867014니나(로얄 크라운)9
867015혜선옹주5
867016아즈사 아이자와7
867022순혜옹주5
\n", "

274635 rows × 2 columns

\n", "" ], "text/plain": [ " title parsed_table_contents\n", "2 “……” 5\n", "6 #Fairy_dancing_in_lake 0\n", "14 &(싱글) 1\n", "18 페텔기우스 로마네콩티 1\n", "19 사테라(Re: 제로부터 시작하는 이세계 생활) 0\n", "... ... ...\n", "867012 마른 남자 0\n", "867014 니나(로얄 크라운) 9\n", "867015 혜선옹주 5\n", "867016 아즈사 아이자와 7\n", "867022 순혜옹주 5\n", "\n", "[274635 rows x 2 columns]" ] }, "execution_count": 232, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 파싱된 결과가 0 이상인 것만 남긴다. \n", "cnt_df = filtered_df[['title', 'parsed_table_contents']]\n", "cnt_df['parsed_table_contents'] = cnt_df['parsed_table_contents'].apply(lambda x: len(x))\n", "cnt_df" ] }, { "cell_type": "code", "execution_count": 233, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
titletexttable_contentsparsed_table_contents
2“……”||<-2><tablebordercolor=#878787><tablealign=ri...[||<-2><tablebordercolor=#878787><tablealign=r...[{'predicate': ' '''코너명''' ', 'objects': ' “……...
14&(싱글)[include(틀:하마사키 아유미의 싱글)]\\n||||||<tablewidth=1...[||||||<tablewidth=100%> '''[[하마사키 아유미]]의 싱글''...[{'predicate': '<width=40%> '''&''' (2003) ', ...
18페텔기우스 로마네콩티[include(틀:다른 뜻1, other1=항성, rd1=베텔게우스)]\\n[inc...[||<tablealign=center><bgcolor=#ffffff> [[파일:페...[{'predicate': '<bgcolor=#007f66> {{{#ffffff '...
21레굴루스 코르니아스[include(틀:대죄주교(Re: 제로부터 시작하는 이세계 생활))]\\n\\n||<...[||<bgcolor=#c0c0c0> {{{#ffffff '''라이트 노벨 설정''...[{'predicate': '<bgcolor=#c0c0c0> {{{#ffffff '...
22에키드나(Re: 제로부터 시작하는 이세계 생활)[include(틀:회원수정)]\\n[include(틀:마녀(Re: 제로부터 시작하는...[||<width=57%><bgcolor=#ffffff> [[파일:에키드나 라노벨 ...[{'predicate': '<width=57%><bgcolor=#ffffff> [...
...............
867005불량배들(리틀 나이트메어 시리즈)||<-2><table width=300><table bordercolor=#000...[||<-2><table width=300><table bordercolor=#00...[{'predicate': '<width=50%> [[파일:Male_Bully.pn...
867014니나(로얄 크라운)[[분류:로얄 크라운]]\\n[include(틀:상위 문서, top1=로얄 크라운)]...[||<tablealign=center><tablewidth=70%><-2><bgc...[{'predicate': ' {{{#000,#fff '''클래스'''}}} ', ...
867015혜선옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...[||<-2><tablealign=right><tablewidth=400><tabl...[{'predicate': '<width=50> '''{{{#gold 본명}}}''...
867016아즈사 아이자와||<table width=100%><width=58%><tablebordercol...[||<table width=100%><width=58%><tableborderco...[{'predicate': '<rowbgcolor=#ffff99> [[전생했더니 슬...
867022순혜옹주[[분류:조선의 후궁]]\\n[include(틀:조선의 후궁(환조 ~ 연산군))]\\n...[||<-2><tablealign=right><tablewidth=400><tabl...[{'predicate': '<width=50> '''{{{#gold 출생}}}''...
\n", "

199604 rows × 4 columns

\n", "
" ], "text/plain": [ " title \\\n", "2 “……” \n", "14 &(싱글) \n", "18 페텔기우스 로마네콩티 \n", "21 레굴루스 코르니아스 \n", "22 에키드나(Re: 제로부터 시작하는 이세계 생활) \n", "... ... \n", "867005 불량배들(리틀 나이트메어 시리즈) \n", "867014 니나(로얄 크라운) \n", "867015 혜선옹주 \n", "867016 아즈사 아이자와 \n", "867022 순혜옹주 \n", "\n", " text \\\n", "2 ||<-2>
'''[[하마사키 아유미]]의 싱글''... \n", "18 [|| [[파일:페... \n", "21 [|| {{{#ffffff '''라이트 노벨 설정''... \n", "22 [|| [[파일:에키드나 라노벨 ... \n", "... ... \n", "867005 [||<-2>
<-2> '''&''' (2003) ', ... \n", "18 [{'predicate': ' {{{#ffffff '... \n", "21 [{'predicate': ' {{{#ffffff '... \n", "22 [{'predicate': ' [... \n", "... ... \n", "867005 [{'predicate': ' [[파일:Male_Bully.pn... \n", "867014 [{'predicate': ' {{{#000,#fff '''클래스'''}}} ', ... \n", "867015 [{'predicate': ' '''{{{#gold 본명}}}''... \n", "867016 [{'predicate': ' [[전생했더니 슬... \n", "867022 [{'predicate': ' '''{{{#gold 출생}}}''... \n", "\n", "[199604 rows x 4 columns]" ] }, "execution_count": 233, "metadata": {}, "output_type": "execute_result" } ], "source": [ "filtered_df = filtered_df[filtered_df['title'].isin(cnt_df[cnt_df['parsed_table_contents']!=0]['title'].unique())]\n", "filtered_df" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def refine_triple(triple):\n", " refined_predicate = re.findall(r\"'''(.*?)'''\", triple['predicate'])\n", " triple_list = []\n", " if not refined_predicate:\n", " return None\n", " else:\n", " refined_predicate = refined_predicate[0]\n", " refined_predicate = refined_predicate.replace('[br]', '')\n", " refined_predicate = refined_predicate.split('|')[0].strip('[[')\n", " if '[[' in triple['objects'] and ']]' not in triple['objects']:\n", " triple['objects'] = triple['objects'] + ']]'\n", " refined_objects = re.findall(r'\\[\\[(.*?)\\]\\]', triple['objects'])\n", " for obj in refined_objects:\n", " triple_list.append({'predicate': refined_predicate, 'objects': obj})\n", " return triple_list\n", "\n", "def get_refine_triple(triples):\n", " triple_list = []\n", " for triple in triples:\n", " refined_triple = refine_triple(triple)\n", " if refined_triple:\n", " for rt in refined_triple:\n", " if rt['objects']:\n", " triple_list.append(rt)\n", " if len(triple_list) == 0:\n", " return None\n", " return triple_list\n", "\n", "def find_korean_text(x):\n", " korean_pattern = re.compile(r\"[가-힣]+\")\n", " korean_matches = korean_pattern.findall(x)\n", " if len(korean_matches) == 0:\n", " return None\n", " return korean_matches[0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "filtered_df['refined_triple'] = filtered_df['parsed_table_contents'].progress_apply(lambda x: get_refine_triple(x))\n", "triple_df = filtered_df[['title', 'refined_triple']].dropna()\n", "triple_df = triple_df.explode('refined_triple')\n", "triple_df['predicate'] = triple_df['refined_triple'].apply(lambda x: x['predicate'])\n", "triple_df['object'] = triple_df['refined_triple'].apply(lambda x: x['objects'])\n", "triple_df = triple_df[['title', 'predicate', 'object']]\n", "triple_df['predicate'] = triple_df['predicate'].progress_apply(lambda x: find_korean_text(x))\n", "triple_df = triple_df.dropna()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "predicate_cnt_df = triple_df.groupby('predicate')['object'].count().reset_index()\n", "filtered_predicates = predicate_cnt_df[predicate_cnt_df['object']>=200]['predicate'].unique()\n", "filtered_triple_df = triple_df[triple_df['predicate'].isin(filtered_predicates)]\n", "filtered_triple_df" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "filtered_triple_object_refined = copy.deepcopy(filtered_triple_df)\n", "filtered_triple_object_refined['object'] = filtered_triple_object_refined['object'].apply(lambda x: x.split('|')[0].strip())\n", "# 오류가 많아보이는 predicate 제외\n", "exclude_predicates = ['가고시마', '가족관계', '닛포', '인간관계', '부모', '가족', '형제자매']\n", "excloude_objects - ['아버지', '어머니', '누나', '형', '동생' '동생', '남동생']\n", "filtered_triple_object_refined = filtered_triple_object_refined[~filtered_triple_object_refined['predicate'].isin(exclude_predicates)]\n", "filtered_triple_object_refined = filtered_triple_object_refined[~filtered_triple_object_refined['object'].isin(exclude_objects)\n", "filtered_triple_object_refined['title'] = filtered_triple_object_refined['title'].apply(lambda x: f'https://namu.wiki/w/{x}')\n", "filtered_triple_object_refined['object'] = filtered_triple_object_refined['object'].apply(lambda x: f'https://namu.wiki/w/{x}')\n", "filtered_triple_object_refined['predicate'] = filtered_triple_object_refined['predicate'].apply(lambda x: f'predicate/{x}')\n", "filtered_triple_object_refined.columns = ['subject', 'predicate', 'object']\n", "filtered_triple_object_refined" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# graphDB에 올리기 위해 rdf 규칙에 맞게 수정. 각종 오류 일으키는 원인 제거\n", "\n", "triple = copy.deepcopy(filtered_triple_object_refined)\n", "triple['subject'] = triple['subject'].apply(lambda x:f\"<{x.replace('<', '').replace('>', '')}>\")\n", "triple['predicate'] = triple['predicate'].apply(lambda x:f\"', '')}>\")\n", "triple['object'] = triple['object'].apply(lambda x:f'<{x}>')\n", "\n", "triple['subject'] = triple['subject'].apply(lambda x: '_'.join(x.split()))\n", "triple['predicate'] = triple['predicate'].apply(lambda x: '_'.join(x.split()))\n", "triple['object'] = triple['object'].apply(lambda x: '_'.join(x.split()))\n", "\n", "\n", "triple = triple[~triple['subject'].str.contains('%|#|\\^|\\{|\\}|`|\\|')]\n", "triple = triple[~triple['object'].str.contains('%|#|\\^|\\{|\\}|`|\\|')]\n", "triple = triple[~triple['object'].str.contains('.jpg')]\n", "triple = triple[~triple['object'].str.contains('.svg')]\n", "triple = triple[~triple['object'].str.contains('.png')]\n", "triple = triple[~triple['object'].str.contains('파일:')]\n", "triple['subject'] = triple['subject'].apply(lambda x: x.replace('\\\\', '').replace('\"', '').replace(']', '').replace('[', ''))\n", "triple['object'] = triple['object'].apply(lambda x: x.replace('\\\\', '').replace('\"', '').replace(']', '').replace('[', ''))\n", "triple = triple[~triple['subject'].str.contains('Réalta_Nua')]\n", "triple = triple[~triple['subject'].str.contains('/Fate/')]\n", "triple['end'] = '.'" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.7" } }, "nbformat": 4, "nbformat_minor": 4 }